package sbc.group1.lab1.alt;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public abstract class AbstractTester implements Runnable {
	public static final Logger log = LoggerFactory
			.getLogger(AbstractTester.class);

	protected final CarService cs;
	private volatile boolean running;

	@Override
	public void run() {
		log.info("Starting");
		running = true;
		while (running) {
			try {
				doWork();
				log.debug("Car test done.");
			} catch (InterruptedException e) {
				log.info("Interrupted! Stopping...");
				running = false;
				return;
			} catch (RemoteException e) {
				log.info("RemoteException! Stopping...");
				running = false;
				return;
			}

		}

	}

	public AbstractTester() throws MalformedURLException, RemoteException,
			NotBoundException {
		cs = (CarService) Naming.lookup("rmi://localhost:1099/CarService");
	}
	
	protected abstract void doWork() throws RemoteException, InterruptedException;

}
